<template>
  <div class="mod-prod-prodTag">
    <avue-crud ref="crud"
               :page="page"
               :data="dataList"
               :table-loading="dataListLoading"
               :option="tableOption"
               @search-change="searchChange"
               @on-load="getDataList"
               @refresh-change="refreshChange">
      <template slot-scope="scope"
                slot="menu">
        <el-button type="primary"
                   size="small"
                   icon="el-icon-edit"
                   @click="audit_Click(scope.row)">审核</el-button>
        <el-button type="primay" size="small" @click="remit(scope.row)">确定打款</el-button>
      </template>
    </avue-crud>
    <audit-withdraw ref="auditWithdraw" v-if="addOrUpdateVisible" @refreshDataList="refreshChange"></audit-withdraw>
  </div>
</template>

<script>
  import { tableOption } from '@/crud/job/withdraw'
  import auditWithdraw from './auditWithdraw'
  export default {
    data () {
      return {
        dataList: [],
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        },
        dataListLoading: false,
        tableOption: tableOption,
        addOrUpdateVisible: false
      }
    },
    components: {
      auditWithdraw
    },
    created () {
    },
    mounted () {
    },
    methods: {
      getDataList (page, params) {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/cash/out/page'),
          method: 'get',
          params: this.$http.adornParams(Object.assign({
            current: page == null ? this.page.currentPage : page.currentPage,
            size: page == null ? this.page.pageSize : page.pageSize
          }, params))
        }).then(({ data }) => {
          console.log(data)
          this.dataList = data.records
          this.page.total = data.total
          this.dataListLoading = false
        })
      },
      // 新增 / 修改
      audit_Click (row) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.auditWithdraw.init(row.id)
        })
      },
      /**
       * 刷新回调
       */
      refreshChange () {
        this.getDataList(this.page)
      },
      searchChange (params) {
        this.getDataList(this.page, params)
      },
      // 确定打款
      remit (row) {
        this.$confirm(`确定进行【已完成打款】操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/cash/out/payment'),
            method: 'post',
            data: this.$http.adornData({
              id: row.id,
              payStatus: 1
            })
          }).then(({ data }) => {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList(this.page)
              }
            })
          })
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
</style>
